package com.example.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.SPUtils;
import com.example.content.Constant;
import com.example.login.ui.login.LoginActivity;
import com.example.xc.R;

/**
 * 设置页面
 */
public class SettingActivity extends AppCompatActivity {


    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        @SuppressLint("UseSwitchCompatOrMaterialCode")
        Switch aSwitch = findViewById(R.id.sv_switch);
        RelativeLayout rlStudent=findViewById(R.id.rl_add_student);
        RelativeLayout rlAddCourse=findViewById(R.id.rl_add_course);
        aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if(isChecked){
                rlStudent.setVisibility(View.VISIBLE);
                rlAddCourse.setVisibility(View.VISIBLE);
            }else{
                rlStudent.setVisibility(View.GONE);
                rlAddCourse.setVisibility(View.GONE);
            }
        });
        findViewById(R.id.back).setOnClickListener(v -> finish());
        Button loginOut = findViewById(R.id.btn_exit);
        loginOut.setOnClickListener(v -> {
            SPUtils.getInstance().put(Constant.isLoginIn, "");
            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            finish();
            Toast.makeText(this, "退出登录成功", Toast.LENGTH_SHORT).show();
        });

        rlStudent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getBaseContext(),RegisterActivity.class);
                intent.putExtra("isRegister",1);
                startActivity(intent);
            }
        });
        rlAddCourse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getBaseContext(),AddCourseActivity.class);
                startActivity(intent);
            }
        });
    }
}